package nsn.message.aggregator.sample.data;

import static org.easymock.EasyMock.createNiceControl;
import static org.easymock.EasyMock.expect;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import nsn.message.aggregator.model.IEntry;
import nsn.message.aggregator.model.ISource;
import nsn.message.aggregator.model.ISourceType;

import org.easymock.IMocksControl;

/**
 *
 * @author Lukasz Nowak
 * @since 13-03-2011
 *
 */
public class DummySourceType implements ISourceType {

    /**
     * 
     */
    private static final long serialVersionUID = -1678178754532807977L;
    final Set<ISource> _sources = new HashSet<ISource>();

    /**
     * TODO Comment me!!!!!!!!!!!
     *
     */
    public DummySourceType() {
        init();
    }

    private void init() {
        final IMocksControl control = createNiceControl();

        {

            {
                final ISource sourceA = control.createMock(ISource.class);
                expect(sourceA.getName()).andReturn("source A").anyTimes();
                expect(sourceA.getType()).andReturn(this).anyTimes();

                {
                    final List<IEntry> entriesA = new ArrayList<IEntry>();
                    {
                        final IEntry a1 = control.createMock(IEntry.class);
                        expect(a1.getAuthor()).andReturn("Sokrates").anyTimes();
                        expect(a1.getContent()).andReturn("x2 + y2 = z2")
                                .anyTimes();
                        expect(a1.getPublishedDate()).andReturn(new Date())
                                .anyTimes();
                        expect(a1.getTitle()).andReturn("Definition")
                                .anyTimes();
                        expect(a1.getSource()).andReturn(sourceA).anyTimes();
                        entriesA.add(a1);
                    }
                    {
                        final IEntry a2 = control.createMock(IEntry.class);
                        expect(a2.getAuthor()).andReturn("Hamlet").anyTimes();
                        expect(a2.getContent())
                                .andReturn("To be or not to be?").anyTimes();
                        expect(a2.getPublishedDate()).andReturn(new Date())
                                .anyTimes();
                        expect(a2.getTitle()).andReturn("Question").anyTimes();
                        expect(a2.getSource()).andReturn(sourceA).anyTimes();
                        entriesA.add(a2);
                    }
                    expect(sourceA.getEntries()).andReturn(entriesA).anyTimes();
                }
                _sources.add(sourceA);
            }
            {
                final ISource sourceB = control.createMock(ISource.class);
                expect(sourceB.getName()).andReturn("source B").anyTimes();
                expect(sourceB.getType()).andReturn(this).anyTimes();
                {
                    final List<IEntry> entriesB = new ArrayList<IEntry>();
                    {
                        final IEntry b1 = control.createMock(IEntry.class);
                        expect(b1.getAuthor()).andReturn("Sokrates").anyTimes();
                        expect(b1.getContent()).andReturn("x2 + y2 = z2")
                                .anyTimes();
                        expect(b1.getPublishedDate()).andReturn(new Date())
                                .anyTimes();
                        expect(b1.getTitle()).andReturn("Definition")
                                .anyTimes();
                        expect(b1.getSource()).andReturn(sourceB).anyTimes();
                        entriesB.add(b1);
                    }
                    {
                        final IEntry b2 = control.createMock(IEntry.class);
                        expect(b2.getAuthor()).andReturn("Hamlet").anyTimes();
                        expect(b2.getContent())
                                .andReturn("To be or not to be?").anyTimes();
                        expect(b2.getPublishedDate()).andReturn(new Date())
                                .anyTimes();
                        expect(b2.getTitle()).andReturn("Question").anyTimes();
                        expect(b2.getSource()).andReturn(sourceB).anyTimes();
                        entriesB.add(b2);
                    }
                    expect(sourceB.getEntries()).andReturn(entriesB).anyTimes();
                }
                _sources.add(sourceB);
            }
        }

        control.replay();
    }

    @Override
    public String getName() {
        return getClass().getSimpleName();
    }

    @Override
    public Set<ISource> getSources() {
        // TODO Auto-generated method stub
        return _sources;
    }


    @Override
    public ISource create(final Map<String, String> params) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String[] parameters() {
        return new String[0];
    }

	@Override
	public void update() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addPropertyChangeListener(final PropertyChangeListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removePropertyChangeListener(final PropertyChangeListener listener) {
		// TODO Auto-generated method stub
		
	}
}
